package com.example.store2.Service.impl;

import com.example.store2.Mapper.AttentionMapper;
import com.example.store2.Mapper.URMapper;
import com.example.store2.Service.AttentionService;
import com.example.store2.pojo.Atten;
import com.example.store2.pojo.Attention;
import com.example.store2.pojo.Resources;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AttentionServiceImpl implements AttentionService {
    @Autowired
    private AttentionMapper attentionMapper;
    @Autowired
    private URMapper urMapper;
    @Override
    public List<Attention> list(Integer id,Integer classesId,String resourcesName) {
        return attentionMapper.list(id,classesId,resourcesName);
    }

    @Override
    public boolean add(Atten atten) {
        Integer userId=atten.getUserId();
        Integer resourcesId=atten.getResourcesId();
        if(urMapper.countadd(userId,resourcesId)!=0){
            return false;
        }
        else{
            Resources resources=new Resources();
            resources.setUserId(userId);
            resources.setId(resourcesId);
            resources.setState("他人");
            urMapper.add(resources);
            return true;
        }
    }
}
